<?php

class Admin_Users_Controller extends Base_Controller {

	public function action_userslist()
	{	
		return View::make('admin.userslist');
	}


	/*
	初始化表格数据,数据表格接口
	*/
	public function action_usersinfo()
	{
		$data = strtotime(Input::get('data'));
		$data1 = strtotime(Input::get('data1'));
		if(empty($data)||empty($data1)){
			$userinfo = DB::table('user_member') ->order_by('time','desc') -> paginate(10);
		}else{
			$userinfo = DB::table('user_member') -> order_by('time','desc') -> where_between('time',$data,$data1) -> paginate(10);
		}
        foreach($userinfo->results as $key => $val){
			if($val['code']==0){
				$userinfo->results[$key]['code'] = "未发货";
			}else{
				$userinfo->results[$key]['code'] = "已发货";
			}
			$userinfo->results[$key]['time'] = date("Y-m-d H:i:s",$val['time']);
        }
        
        return json_encode(array('code'=>0,'msg'=>'','count'=> $userinfo->total,'data'=>$userinfo->results));

	}



	public function action_changeuser()
	{
		$id = Input::get('id');
		$userinfo = DB::table('user_member')->where('id','=',$id)->first();
		return View::make('admin.user_member',array('userinfo'=>$userinfo));
	}

	public function action_dochange()
	{
		$id = Input::get('userid');
		$userupdate = DB::table('user_member')->where('id','=',$id)->update(array('phone'=>Input::get('phone'),'username'=>Input::get('username'),'address'=>Input::get('address'),'code'=>Input::get('interest')));
		if($userupdate){
			return View::make('jump.success',array('msg'=>'修改成功','time'=>2,'url'=>'/weixinapp/public/index.php/admin/users/userslist'));
		}else{
			return View::make('jump.error',array('msg'=>'修改失败','time'=>2));
		}
	}

	public function action_dele()
	{
		$id = Input::get('id');
		$deleuser = DB::table('user_member')->where('id','=',$id)->delete();
		if($deleuser){
			return  json_encode(array('code'=>200,'msg'=>'删除成功'));
		}else{
			return json_encode(array('code'=>400,'msg'=>'删除失败'));
		}
	}




}